/**
 * 版权所有 2009-2012山东新北洋信息技术股份有限公司
 * 保留所有权利。
 */
package com.linyaonan.leetcode.easy._217;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * @ProjectName: leetcode
 * @Package: com.linyaonan.leetcode.easy._217
 * @ClassName: ContainsDuplicate
 * @Author: linyaonan
 * @Date: 2019/12/13 10:31
 */
public class ContainsDuplicate {
    public boolean containsDuplicate(int[] nums) {
        if (nums == null || nums.length == 0 || nums.length == 1) {
            return false;
        }
        Map<Integer, Integer> hashMap = new HashMap<>();
        for (int num : nums) {
            if (hashMap.containsKey(num)) {
                return true;
            } else {
                hashMap.put(num, 1);
            }
        }
        return false;
    }

    public boolean containsDuplicate1(int[] nums) {
        Arrays.sort(nums);
        boolean flag = false;
        for (int i = 1; i < nums.length; i++) {
            if (nums[i - 1] == nums[i]) {
                flag = true;
            }
        }
        return flag;
    }
}
